package com.briup.day12;

import java.util.Objects;

/**
 * 存储学生信息，并不能重复学生信息
 * @author lining
 * @date 2024/1/23 14:44
 */
public class Student implements Comparable<Student>{
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public int compareTo(Student o) {
        // this 新添加元素    o 原来的元素
        //    id=2            id=5   = -3
//        return this.id - o.id;//表示小-》大
//        return -(this.id - o.id);
        //实现由字母 a-z  bob  jack tom String
       Comparable c = this.name;
       return  c.compareTo(o.name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
